
package cn.snmp.mutual.constants;

import cn.snmp.mutual.data.ObjService;

/**
 * @author dengkn
 * SNMP 错误吗设置，这个需要和设备实现确认，不同的厂家错误码不一样
 * */
 public class NnTempLetError {
    public static final int SNMP_ERR_NOERROR = 0;

    public static final int SNMP_ERR_TOOBIG = 1;

    public static final int SNMP_ERR_NOSUCHNAME = 2;

    public static final int SNMP_ERR_BADVALUE = 3;

    public static final int SNMP_ERR_READONLY = 4;

    public static final int SNMP_ERR_GENERR = 5;

    public static final int SNMP_ERR_NOACCESS = 6;

    public static final int SNMP_ERR_WRONGTYPE = 7;

    public static final int SNMP_ERR_WRONGLENGTH = 8;

    public static final int SNMP_ERR_WRONGENCODING = 9;

    public static final int SNMP_ERR_WRONGVALUE = 10;

    public static final int SNMP_ERR_NOCREATION = 11;

    public static final int SNMP_ERR_INCONSISTENTVALUE = 12;

    public static final int SNMP_ERR_RESOURCEUNAVAILABLE = 13;

    public static final int SNMP_ERR_COMMITFAILED = 14;

    public static final int SNMP_ERR_UNDOFAILED = 15;

    public static final int SNMP_ERR_AUTHORIZATIONERROR = 16;

    public static final int SNMP_ERR_NOTWRITABLE = 17;

    public static final int SNMP_ERR_INCONSISTENTNAME = 18;

    public static final int SNMP_NOT_INIT = 19;

    public static final int INVALID_VERSION = 20;

    public static final int OID_NOT_SPECIFIED = 21;

    public static final int REQ_TIMEDOUT = 22;

    public static final int INVALID_V1_REQ = 23;

    public static final int EMPTY_VAR_BIND = 24;

    public static final int INVALID_NON_REP = 25;

    public static final int EMPTY_DATA = 26;

    public static final int VAR_BIND_OUT_OF_RANGE = 27;

    public static final int EMPTY_VARIABLE = 28;

    public static final int INVALID_NUMERIC_VAL = 29;

    public static final int MIB_NODE_UNAVAIL = 30;

    public static final int OID_NOT_LEAF = 31;

    public static final int ERR_CREATING_VARIABLE = 32;

    public static final int ILLEGAL_ARG = 33;

    public static final int INVALID_GENERIC_TYPE = 34;

    public static final int IP_ADDR_NOT_SPECIFIED = 35;

    public static final int SESSION_REMOTE_HOST_UNKNOWN = 36;

    public static final int SECURITYEXP_CONNECTING_REMOTE_HOST = 37;

    public static final int IO_ERROR = 38;

    public static final int INVALID_TABLE_OID = 39;

    public static final int EXT_INDEX_UNAVAIL = 40;

    public static final int INVALID_CONTEXT_NAME = 41;

    public static final int INVALID_CONTEXT_ID = 42;

    public static final int UNKNOWN_ERR = 43;

    public static final int UNSUPP_SECLEVEL_ERR = 44;

    public static final int NOT_IN_TIME_WINDOWS_ERR = 45;

    public static final int UKNOWN_USERNAMES_ERR = 46;

    public static final int UKNOWN_ENGINEID_ERR = 47;

    public static final int WRONG_DIGEST_ERR = 48;

    public static final int DECRYPT_ERROR_ERR = 49;

    public static final int ASN1_ERROR_ERR = 50;

    public static final int DISCOVERY_FAILED = 51;

    public static final int TIME_SYNC_FAILED = 52;

    public static final int NOSUCHOBJECTEXP = 128;

    public static final int NOSUCHINSTANCEEXP = 129;

    public static final int ENDOFMIBVIEWEXP = 130;

    public static final int NO_ERR_REGISTERED = -1;

    public static final int PARAM_NOT_FOUND = 811;

    public static final int MIB_CINFIG_FILE_NOT_FOUND = 1000;

    public static final int PARSE_MIB_CINFIG_FILE_FAILED = 1001;

    public static final int MIB_TABLE_NOT_FOUND = 1002;

    public static final int MIB_NODE_NOT_FOUND = 1003;

    public static final int INIT_SNMPTARGET_ERROR = 1004;

    public static final int TABLE_TYPE_ERROR = 1005;

    public static final int MIBNODEADAPTER_READ_ERROR = 1006;

    public static final int MIBNODEADAPTER_WRITE_ERROR = 1007;

    public static final int AGENT_REPONSE_ERROR = 1008;

    public static final int NETEMPLET_UNKNOWN_ERROR = 1009;

    public static final int SNMP_NODE_NOT_FOUND = 2000;

    /**
     * 创建并返回结果对象
     *
     * @param errCode 错误码
     * @param errDesc 错误描述
     * @return 结果对象
     */
    public static ObjService buildResult(String errCode, String errDesc) {
        ObjService result = new ObjService("Result");
        result.setValue("ErrCode", errCode);
        result.setValue("ErrDesc", errDesc);
        return result;
    }

    /**
     * 设置返回结果
     *
     * @param result  结果对象
     * @param errCode 错误码
     * @param errDesc 错误描述
     */
    public static void setResult(ObjService result, String errCode, String errDesc) {
        result.setValue("ErrCode", errCode);
        result.setValue("ErrDesc", errDesc);
    }

    /**
     * 根据结果取得错误码
     *
     * @param result 结果信息
     * @return 错误码
     */
    public static String getErrCode(ObjService result) {
        return result.getStringValue("ErrCode");
    }

    /**
     * 根据结果信息取得错误描述
     *
     * @param result 结果信息
     * @return 错误描述
     */
    public static String getErrDesc(ObjService result) {
        return result.getStringValue("errDesc");
    }

    /**
     * 根据错误码取得错误信息。
     *
     * @param errCode
     * @return 错误描述
     */
    public static String getErrorMessage(int errCode) {
        String errMessage = "";
        switch (errCode) {
            case 0:
                errMessage = "SNMP_ERR_NOERROR";
                break;
            case 1:
                errMessage = "SNMP_ERR_TOOBIG";
                break;
            case 2:
                errMessage = "SNMP_ERR_NOSUCHNAME";
                break;
            case 3:
                errMessage = "SNMP_ERR_BADVALUE";
                break;
            case 4:
                errMessage = "SNMP_ERR_READONLY";
                break;
            case 5:
                errMessage = "SNMP_ERR_GENERR";
                break;
            case 6:
                errMessage = "SNMP_ERR_NOACCESS";
                break;
            case 7:
                errMessage = "SNMP_ERR_WRONGTYPE";
                break;
            case 8:
                errMessage = "SNMP_ERR_WRONGLENGTH";
                break;
            case 9:
                errMessage = "SNMP_ERR_WRONGENCODING";
                break;
            case 10:
                errMessage = "SNMP_ERR_WRONGVALUE";
                break;
            case 11:
                errMessage = "SNMP_ERR_NOCREATION";
                break;
            case 12:
                errMessage = "SNMP_ERR_INCONSISTENTVALUE";
                break;
            case 13:
                errMessage = "SNMP_ERR_RESOURCEUNAVAILABLE";
                break;
            case 14:
                errMessage = "SNMP_ERR_COMMITFAILED";
                break;
            case 15:
                errMessage = "SNMP_ERR_UNDOFAILED";
                break;
            case 16:
                errMessage = "SNMP_ERR_AUTHORIZATIONERROR";
                break;
            case 17:
                errMessage = "SNMP_ERR_NOTWRITABLE";
                break;
            case 18:
                errMessage = "SNMP_ERR_INCONSISTENTNAME";
                break;
            case 19:
                errMessage = "SNMP_NOT_INIT";
                break;
            case 20:
                errMessage = "INVALID_VERSION";
                break;
            case 21:
                errMessage = "OID_NOT_SPECIFIED";
                break;
            case 22:
                errMessage = "REQ_TIMEDOUT";
                break;
            case 23:
                errMessage = "INVALID_V1_REQ";
                break;
            case 24:
                errMessage = "EMPTY_VAR_BIND";
                break;
            case 25:
                errMessage = "INVALID_NON_REP";
                break;
            case 26:
                errMessage = "EMPTY_DATA";
                break;
            case 27:
                errMessage = "VAR_BIND_OUT_OF_RANGE";
                break;
            case 28:
                errMessage = "EMPTY_VARIABLE";
                break;
            case 29:
                errMessage = "INVALID_NUMERIC_VAL";
                break;
            case 30:
                errMessage = "MIB_NODE_UNAVAIL";
                break;
            case 31:
                errMessage = "OID_NOT_LEAF";
                break;
            case 32:
                errMessage = "ERR_CREATING_VARIABLE";
                break;
            case 33:
                errMessage = "ILLEGAL_ARG";
                break;
            case 34:
                errMessage = "INVALID_GENERIC_TYPE";
                break;
            case 35:
                errMessage = "IP_ADDR_NOT_SPECIFIED";
                break;
            case 36:
                errMessage = "SESSION_REMOTE_HOST_UNKNOWN";
                break;
            case 37:
                errMessage = "SECURITYEXP_CONNECTING_REMOTE_HOST";
                break;
            case 38:
                errMessage = "IO_ERROR";
                break;
            case 39:
                errMessage = "INVALID_TABLE_OID";
                break;
            case 40:
                errMessage = "EXT_INDEX_UNAVAIL";
                break;
            case 41:
                errMessage = "INVALID_CONTEXT_NAME";
                break;
            case 42:
                errMessage = "INVALID_CONTEXT_ID";
                break;
            case 43:
                errMessage = "UNKNOWN_ERR";
                break;
            case 44:
                errMessage = "UNSUPP_SECLEVEL_ERR";
                break;
            case 45:
                errMessage = "NOT_IN_TIME_WINDOWS_ERR";
                break;
            case 46:
                errMessage = "UKNOWN_USERNAMES_ERR";
                break;
            case 47:
                errMessage = "UKNOWN_ENGINEID_ERR";
                break;
            case 48:
                errMessage = "WRONG_DIGEST_ERR";
                break;
            case 49:
                errMessage = "DECRYPT_ERROR_ERR";
                break;
            case 50:
                errMessage = "ASN1_ERROR_ERR";
                break;
            case 51:
                errMessage = "DISCOVERY_FAILED";
                break;
            case 52:
                errMessage = "TIME_SYNC_FAILED";
                break;
            case 128:
                errMessage = "NOSUCHOBJECTEXP";
                break;
            case 129:
                errMessage = "NOSUCHINSTANCEEXP";
                break;
            case 130:
                errMessage = "ENDOFMIBVIEWEXP";
                break;
            case 1000:
                errMessage = "MIB_CINFIG_FILE_NOT_FOUND";
                break;
            case 1001:
                errMessage = "PARSE_MIB_CINFIG_FILE_FAILED";
                break;
            case 1002:
                errMessage = "MIB_TABLE_NOT_FOUND";
                break;
            case 1003:
                errMessage = "MIB_NODE_NOT_FOUND";
                break;
            case 1004:
                errMessage = "INIT_SNMPTARGET_ERROR";
                break;
            case 1005:
                errMessage = "TABLE_TYPE_ERROR";
                break;
            case -1:
                errMessage = "NO_ERR_REGISTERED";
                break;
            case MIBNODEADAPTER_READ_ERROR:
                errMessage = "MIBNODEADAPTER_READ_ERROR";
                break;
            case MIBNODEADAPTER_WRITE_ERROR:
                errMessage = "MIBNODEADAPTER_WRITE_ERROR";
                break;
            case AGENT_REPONSE_ERROR:
                errMessage = "AGENT_REPONSE_ERROR";
                break;
            default:
                errMessage = "Cannot find the spical ErrorCode...";
                break;
        }

        return errMessage;
    }
}
